RTOS_DIR=../FreeRTOS
RTOS_SOURCE_DIR=$(RTOS_DIR)/Source
SW_DIR=../SW
SW_INC_DIR=$(SW_DIR)/inc
SW_UTILS_DIR=$(SW_DIR)/utils
SW_DRIVERLIB_DIR=$(SW_DIR)/driverlib

CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
LDSCRIPT=standalone.ld

# should use --gc-sections but the debugger does not seem to be able to cope with the option.
LINKER_FLAGS=-nostartfiles -Xlinker -oheatcontrol.axf -Xlinker -M -Xlinker -Map=heatcontrol.map -Xlinker --no-gc-sections

DEBUG=-g
OPTIM=-O0


CFLAGS=-Wall $(DEBUG) -I . -I ./controller -I $(RTOS_SOURCE_DIR)/include -I $(RTOS_SOURCE_DIR)/portable/GCC/ARM_CM3 \
		-D GCC_ARMCM3_LM3S102 -D inline= -mthumb -mcpu=cortex-m3 $(OPTIM) -T$(LDSCRIPT) \
		-D PACK_STRUCT_END=__attribute\(\(packed\)\) -D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) -D sprintf=usprintf -D snprintf=usnprintf -D printf=uipprintf \
		-ffunction-sections -fdata-sections -I $(SW_DIR) -I $(SW_DRIVERLIB_DIR) -I $(SW_INC_DIR) -I $(SW_UTILS_DIR)

SOURCE=	main.c \
		infrastructure.c \
		Controller.c \
		TemperatureMonitor.c \
		DisplayManager.c \
		ConsoleManager.c \
		HAL.c \
		KeypadManager.c \
		fixedpoint.c \
		controller/HeatControl.c \
		drivers/rit128x96x4.c \
		$(SW_UTILS_DIR)/ustdlib.c \
		$(SW_UTILS_DIR)/uartstdio.c \
		$(RTOS_SOURCE_DIR)/list.c \
		$(RTOS_SOURCE_DIR)/queue.c \
		$(RTOS_SOURCE_DIR)/tasks.c \
		$(RTOS_SOURCE_DIR)/portable/GCC/ARM_CM3/port.c \
		$(RTOS_SOURCE_DIR)/portable/MemMang/heap_2.c

LIBS= $(SW_DRIVERLIB_DIR)/gcc/libdriver.a

OBJS = $(SOURCE:.c=.o)

all: heatcontrol.bin
	 
heatcontrol.bin : heatcontrol.axf
	$(OBJCOPY) heatcontrol.axf -O binary heatcontrol.bin

heatcontrol.axf : $(OBJS) startup.o Makefile
	$(CC) $(CFLAGS) $(OBJS) startup.o $(LIBS) $(LINKER_FLAGS)

$(OBJS) : %.o : %.c Makefile FreeRTOSConfig.h
	$(CC) -c $(CFLAGS) $< -o $@

startup.o : startup.c Makefile
	$(CC) -c $(CFLAGS) -O1 startup.c -o startup.o
		
clean :
	touch Makefile
	rm $(OBJS) startup.o *.axf *.bin *.map
